package com.example.practical_training_projects.controller;
import com.example.practical_training_projects.service.testService;
import com.example.practical_training_projects.vo.votestclass;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.practical_training_projects.entity.test;
import java.util.List;

@RestController
@CrossOrigin //允许跨域执行
@RequestMapping("test")
public class testController {
    @Autowired
    private testService service;
    /**
     *  返回所有问卷信息：http://localhost:8080/test/list get请求
     *  添加问卷信息：http://localhost:8080/test/add post请求
     *  删除问卷信息 http://localhost:8080/test/del/{{t_uid}} get请求
     *  修改问卷信息 http://localhost:8080/test/update post请求
     *  获取问卷uid http://localhost:8080/test/get/{{t_uid}} get请求

     **/

    @GetMapping("/list")
    public List<votestclass> findAlltestAndclass(Integer ts_uid, String t_context){
        return service.findtestBycontextAndclassuid(ts_uid,t_context);
    }
    //分页
    @GetMapping("/page")
    public PageInfo<votestclass> gettestpage(Integer pageNum, Integer pageSize){
        PageInfo<votestclass> pageInfo = service.findtestpage(pageNum,pageSize);
        return pageInfo;
    }

    @GetMapping("/del/{t_uid}")
    public  Integer deleteTest(@PathVariable("t_uid") Integer t_uid){
        return service.deleteTest(t_uid);
    }

    @PostMapping("add")
    public Integer insertTest(@RequestBody test t_uid) {
        //@RequestBody能接收转换的字符串，匹配到StudentInfo studentInfo中
        return service.insertTest(t_uid);
    }

    @GetMapping("/get/{t_uid}")
    public test findTestuid(@PathVariable("t_uid") Integer t_uid){
        return service.findTestuid(t_uid);
    }

    @PostMapping("update")
    public Integer updateTest(@RequestBody test test1){
        return service.updateTest(test1);
    }

    @GetMapping("/query/{context}")
    public List<test> getContext(@PathVariable("context")String t_context){
        return service.getContest(t_context);
    }

    @GetMapping("/find/{class}")
    public List<test> getClass(@PathVariable("class")String t_class){
        return service.getClass(t_class);
    }

    @GetMapping("Find/{id}")
    public  List<votestclass> findAlltestAndclass(@PathVariable("id") Integer t_uid){
        return service.findAlltestAndclass();
    }
    }


